{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}E:\Github\Bolivia\00_replication_files\log-files/2_Figure_1.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}25 Jan 2022, 21:28:45
{txt}
{com}. 
. timer on 2
{txt}
{com}. 
. *----------*
. * Figure 1 *
. *----------*
.         * Figure 1a
.         *----------
.                 * Master data
.                 use "data/outputs/computo_ulttranstrepdate_missingsatmunmedian.dta", clear
{txt}
{com}. 
.                 * Trimming
.                 cumul trep_date_ulttrans, gen(cum_date)
{txt}
{com}.                 drop if cum_date <= 0.02 | cum_date >= 0.98
{txt}(1,387 observations deleted)

{com}.                 drop cum_date
{txt}
{com}.                         
.                 * Margin
.                 gen mmargin_nbnn_so = mshare_nbnn_so - cshare_nbnn_so
{txt}(3 missing values generated)

{com}. 
.                 * Without this, Stata can't calculate the right ROT bandwidth
.                 su trep_date_ulttrans, d

                {txt}Last transmission time stamp
{hline 61}
      Percentiles      Smallest
 1%    {res} 1.89e+12       1.89e+12
{txt} 5%    {res} 1.89e+12       1.89e+12
{txt}10%    {res} 1.89e+12       1.89e+12       {txt}Obs         {res}     33,168
{txt}25%    {res} 1.89e+12       1.89e+12       {txt}Sum of Wgt. {res}     33,168

{txt}50%    {res} 1.89e+12                      {txt}Mean          {res} 1.89e+12
                        {txt}Largest       Std. Dev.     {res}  2474736
{txt}75%    {res} 1.89e+12       1.89e+12
{txt}90%    {res} 1.89e+12       1.89e+12       {txt}Variance      {res} 6.12e+12
{txt}95%    {res} 1.89e+12       1.89e+12       {txt}Skewness      {res} .1012129
{txt}99%    {res} 1.89e+12       1.89e+12       {txt}Kurtosis      {res} 2.749301
{txt}
{com}.                 local global_mean = r(mean)
{txt}
{com}.                 local global_sd = r(sd)
{txt}
{com}.                 gen trep_date_ulttrans_norm = (trep_date_ulttrans - `global_mean') / `global_sd'
{txt}
{com}. 
.                 * Restrict to regression sample
.                 quietly reg mmargin_nbnn_so $controls_educ trep_date_ulttrans_norm
{txt}
{com}.                 keep if e(sample)
{txt}(1,130 observations deleted)

{com}.                 
.                 * Binned data using binsreg and all booths
.                 binsreg mmargin_nbnn_so trep_date_ulttrans_norm, ///
>                         savedata(temp) replace
{txt}Sorting dataset on trep_date_ulttrans_norm...
Note: This step is omitted if dataset already sorted by trep_date_ulttrans_norm.
{res}
{txt}Binscatter plot
Bin selection method: IMSE-optimal plug-in choice
Placement: Quantile-spaced
Derivative: 0
Output file: temp.dta

{hline 30}{c TT}{hline 15}
{lalign 1:# of observations}{col 30} {c |} {col 32}{res}  32038
{txt}{lalign 1:# of distinct values}{col 30} {c |} {col 32}{res}   9872
{txt}{lalign 1:# of clusters}{col 30} {c |} {col 32}{res}      .
{txt}{hline 30}{c +}{hline 15}
{lalign 1:Bin selection:}{col 30} {c |} 
{ralign 29:Degree of polynomial}{col 30} {c |} {col 32}{res}      0
{txt}{ralign 29:# of smoothness constraints}{col 30} {c |} {col 32}{res}      0
{txt}{ralign 29:# of bins}{col 30} {c |} {col 32}{res}     39
{txt}{hline 30}{c BT}{hline 15}

{hline 9}{c TT}{hline 30}
{col 10}{c |}{col 17}p{col 25}s{col 33}df
{hline 9}{c +}{hline 30}
{lalign 1: dots}{col 10}{c |}{col 17}0{col 25}0{col 33}39
{hline 9}{c BT}{hline 30}
{res}{txt}
{com}. 
.                 * Tack binned data output on to the end of the main data set    
.                 gen dots_binid = _n
{txt}
{com}.                 merge 1:1 dots_binid using "temp.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          31,999
{txt}{col 9}from master{col 30}{res}          31,999{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}              39{txt}  (_merge==3)
{col 5}{hline 41}

{com}.                 drop _merge
{txt}
{com}.                 erase "temp.dta"
{txt}
{com}. 
.                 * Semiparametric Robinson estimate
.                 semipar mmargin_nbnn_so $controls_educ, ///
>                         nonpar(trep_date_ulttrans_norm) nograph generate(yhat) ///
>                         partial(yhat_parout1)

{txt}{col 55} Number of obs ={res}   32038
{txt}{col 55} R-squared     ={res}  0.5293
{txt}{col 55} Adj R-squared ={res}  0.5291
{txt}{col 55} Root MSE      ={res}  0.3008
{txt}{hline 16}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}mmargin_nbnn_so{col 17}{c |}      Coef.{col 29}   Std. Err.{col 41}      t{col 49}   P>|t|{col 57}     [95% Con{col 70}f. Interval]
{hline 16}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 5}ln_density {c |}{col 17}{res}{space 2}-.1168062{col 29}{space 2}  .002103{col 40}{space 1}  -55.54{col 49}{space 3}0.000{col 57}{space 4}-.1209281{col 70}{space 3}-.1126843
{txt}{space 5}ln_aglabor {c |}{col 17}{res}{space 2}-.1091102{col 29}{space 2} .0048185{col 40}{space 1}  -22.64{col 49}{space 3}0.000{col 57}{space 4}-.1185545{col 70}{space 3}-.0996658
{txt}{space 9}logpop {c |}{col 17}{res}{space 2} .0689465{col 29}{space 2} .0030447{col 40}{space 1}   22.64{col 49}{space 3}0.000{col 57}{space 4} .0629788{col 70}{space 3} .0749143
{txt}ln_dist_capital {c |}{col 17}{res}{space 2}-.0449444{col 29}{space 2} .0035431{col 40}{space 1}  -12.68{col 49}{space 3}0.000{col 57}{space 4} -.051889{col 70}{space 3}-.0379997
{txt}{space 2}capital_depto {c |}{col 17}{res}{space 2}-.4089509{col 29}{space 2} .0153544{col 40}{space 1}  -26.63{col 49}{space 3}0.000{col 57}{space 4}-.4390462{col 70}{space 3}-.3788556
{txt}{space 6}medialuna {c |}{col 17}{res}{space 2}-.2952507{col 29}{space 2} .0047316{col 40}{space 1}  -62.40{col 49}{space 3}0.000{col 57}{space 4}-.3045248{col 70}{space 3}-.2859765
{txt}{space 6}Inscritos {c |}{col 17}{res}{space 2}-.0000217{col 29}{space 2} .0000517{col 40}{space 1}   -0.42{col 49}{space 3}0.674{col 57}{space 4} -.000123{col 70}{space 3} .0000796
{txt}{space 2}analfabetismo {c |}{col 17}{res}{space 2} .0094231{col 29}{space 2} .0008072{col 40}{space 1}   11.67{col 49}{space 3}0.000{col 57}{space 4}  .007841{col 70}{space 3} .0110052
{txt}{space 8}ed_prim {c |}{col 17}{res}{space 2} .0181906{col 29}{space 2} .0005074{col 40}{space 1}   35.85{col 49}{space 3}0.000{col 57}{space 4}  .017196{col 70}{space 3} .0191852
{txt}{space 9}ed_sec {c |}{col 17}{res}{space 2} .0056085{col 29}{space 2}  .000449{col 40}{space 1}   12.49{col 49}{space 3}0.000{col 57}{space 4} .0047284{col 70}{space 3} .0064885
{txt}{hline 16}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. 
.                 * Optimal bins for the partialled-out DV        
.                 binsreg yhat_parout1 trep_date_ulttrans_norm, ///
>                         savedata(temp) replace
{txt}Sorting dataset on trep_date_ulttrans_norm...
Note: This step is omitted if dataset already sorted by trep_date_ulttrans_norm.
{res}
{txt}Binscatter plot
Bin selection method: IMSE-optimal plug-in choice
Placement: Quantile-spaced
Derivative: 0
Output file: temp.dta

{hline 30}{c TT}{hline 15}
{lalign 1:# of observations}{col 30} {c |} {col 32}{res}  32038
{txt}{lalign 1:# of distinct values}{col 30} {c |} {col 32}{res}   9872
{txt}{lalign 1:# of clusters}{col 30} {c |} {col 32}{res}      .
{txt}{hline 30}{c +}{hline 15}
{lalign 1:Bin selection:}{col 30} {c |} 
{ralign 29:Degree of polynomial}{col 30} {c |} {col 32}{res}      0
{txt}{ralign 29:# of smoothness constraints}{col 30} {c |} {col 32}{res}      0
{txt}{ralign 29:# of bins}{col 30} {c |} {col 32}{res}     27
{txt}{hline 30}{c BT}{hline 15}

{hline 9}{c TT}{hline 30}
{col 10}{c |}{col 17}p{col 25}s{col 33}df
{hline 9}{c +}{hline 30}
{lalign 1: dots}{col 10}{c |}{col 17}0{col 25}0{col 33}27
{hline 9}{c BT}{hline 30}
{res}{txt}
{com}. 
.                 * Rename to make room for the new bin locations and binned means
.                 drop dots_isknot
{txt}
{com}.                 rename dots_x dots_x_nocontrols
{res}{txt}
{com}.                 rename dots_fit dots_fit_nocontrols
{res}{txt}
{com}. 
.                 * Merge new bin locations and binned means
.                 merge 1:1 dots_binid using "temp.dta"
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          32,011
{txt}{col 9}from master{col 30}{res}          32,011{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}              27{txt}  (_merge==3)
{col 5}{hline 41}

{com}.                 drop _merge
{txt}
{com}.                 erase "temp.dta"
{txt}
{com}. 
.                 * lp robust: partialed out dv
.                 lprobust yhat_parout1 trep_date_ulttrans_norm, ///
>                         genvars eval(dots_x)
{res}
Local Polynomial Regression Estimation and Inference.

{txt}{lalign 1: Sample size                              (n=)    }{col 19}{res}          32038
{txt}{lalign 1: Polynomial order for point estimation    (p=)    }{col 19}{res}              1
{txt}{lalign 1: Order of derivative estimated            (v=)    }{col 19}{res}              0
{txt}{lalign 1: Polynomial order for confidence interval (q=)    }{col 19}{res}              2
{txt}{lalign 1: Kernel function                                  }{col 19}{res}{ralign 15: Epanechnikov}
{txt}{lalign 1: Bandwidth selection method                       }{col 19}{res}{ralign 15: imse-dpi}

{txt}{hline 72}
{ralign 4: }{col 4}{ralign 10: }{col 14}{ralign 10: }{col 24}{ralign 8: }{col 32}{ralign 10: Point}{col 42}{ralign 10: Std.}{col 52}{ralign 20: Robust B.C.}{col 72}
{ralign 4: }{col 4}{ralign 10: eval}{col 14}{ralign 10: bw}{col 24}{ralign 8: Eff.n}{col 32}{ralign 10: Est.}{col 42}{ralign 10: Error}{col 52}{ralign 20: 95% Conf. Interval}{col 72}
{hline 72}
   1{col 4}{res}   -2.0349{col 14}    1.3082{col 24}    7282{col 32}    0.0419{col 42}    0.0084{col 52}    0.0237{col 62}    0.0563{col 72}
{txt}   2{col 4}{res}   -1.4940{col 14}    1.3082{col 24}   13881{col 32}    0.0446{col 42}    0.0044{col 52}    0.0300{col 62}    0.0480{col 72}
{txt}   3{col 4}{res}   -1.2473{col 14}    1.3082{col 24}   17046{col 32}    0.0535{col 42}    0.0034{col 52}    0.0429{col 62}    0.0577{col 72}
{txt}   4{col 4}{res}   -1.0740{col 14}    1.3082{col 24}   19051{col 32}    0.0615{col 42}    0.0030{col 52}    0.0541{col 62}    0.0675{col 72}
{txt}   5{col 4}{res}   -0.9316{col 14}    1.3082{col 24}   20624{col 32}    0.0683{col 42}    0.0027{col 52}    0.0624{col 62}    0.0749{col 72}
{txt}{hline 72}
   6{col 4}{res}   -0.8056{col 14}    1.3082{col 24}   21898{col 32}    0.0744{col 42}    0.0025{col 52}    0.0700{col 62}    0.0819{col 72}
{txt}   7{col 4}{res}   -0.6877{col 14}    1.3082{col 24}   22885{col 32}    0.0801{col 42}    0.0023{col 52}    0.0772{col 62}    0.0886{col 72}
{txt}   8{col 4}{res}   -0.5834{col 14}    1.3082{col 24}   23715{col 32}    0.0851{col 42}    0.0022{col 52}    0.0831{col 62}    0.0943{col 72}
{txt}   9{col 4}{res}   -0.4833{col 14}    1.3082{col 24}   24380{col 32}    0.0899{col 42}    0.0021{col 52}    0.0885{col 62}    0.0993{col 72}
{txt}  10{col 4}{res}   -0.3870{col 14}    1.3082{col 24}   24936{col 32}    0.0943{col 42}    0.0020{col 52}    0.0933{col 62}    0.1040{col 72}
{txt}{hline 72}
  11{col 4}{res}   -0.2952{col 14}    1.3082{col 24}   25377{col 32}    0.0983{col 42}    0.0020{col 52}    0.0974{col 62}    0.1078{col 72}
{txt}  12{col 4}{res}   -0.2041{col 14}    1.3082{col 24}   25730{col 32}    0.1023{col 42}    0.0020{col 52}    0.1009{col 62}    0.1113{col 72}
{txt}  13{col 4}{res}   -0.1158{col 14}    1.3082{col 24}   25890{col 32}    0.1058{col 42}    0.0019{col 52}    0.1044{col 62}    0.1148{col 72}
{txt}  14{col 4}{res}   -0.0246{col 14}    1.3082{col 24}   25999{col 32}    0.1092{col 42}    0.0019{col 52}    0.1078{col 62}    0.1181{col 72}
{txt}  15{col 4}{res}    0.0676{col 14}    1.3082{col 24}   25949{col 32}    0.1125{col 42}    0.0020{col 52}    0.1108{col 62}    0.1212{col 72}
{txt}{hline 72}
  16{col 4}{res}    0.1630{col 14}    1.3082{col 24}   25728{col 32}    0.1156{col 42}    0.0020{col 52}    0.1137{col 62}    0.1242{col 72}
{txt}  17{col 4}{res}    0.2621{col 14}    1.3082{col 24}   25439{col 32}    0.1187{col 42}    0.0020{col 52}    0.1161{col 62}    0.1268{col 72}
{txt}  18{col 4}{res}    0.3635{col 14}    1.3082{col 24}   24937{col 32}    0.1216{col 42}    0.0021{col 52}    0.1184{col 62}    0.1294{col 72}
{txt}  19{col 4}{res}    0.4703{col 14}    1.3082{col 24}   24305{col 32}    0.1247{col 42}    0.0022{col 52}    0.1205{col 62}    0.1318{col 72}
{txt}  20{col 4}{res}    0.5895{col 14}    1.3082{col 24}   23496{col 32}    0.1283{col 42}    0.0023{col 52}    0.1227{col 62}    0.1344{col 72}
{txt}{hline 72}
  21{col 4}{res}    0.7167{col 14}    1.3082{col 24}   22379{col 32}    0.1324{col 42}    0.0024{col 52}    0.1252{col 62}    0.1374{col 72}
{txt}  22{col 4}{res}    0.8556{col 14}    1.3082{col 24}   21035{col 32}    0.1370{col 42}    0.0025{col 52}    0.1287{col 62}    0.1415{col 72}
{txt}  23{col 4}{res}    1.0056{col 14}    1.3082{col 24}   19359{col 32}    0.1424{col 42}    0.0027{col 52}    0.1325{col 62}    0.1461{col 72}
{txt}  24{col 4}{res}    1.1845{col 14}    1.3082{col 24}   17180{col 32}    0.1491{col 42}    0.0030{col 52}    0.1373{col 62}    0.1520{col 72}
{txt}  25{col 4}{res}    1.4094{col 14}    1.3082{col 24}   14403{col 32}    0.1581{col 42}    0.0035{col 52}    0.1446{col 62}    0.1611{col 72}
{txt}{hline 72}
  26{col 4}{res}    1.7048{col 14}    1.3082{col 24}   10886{col 32}    0.1721{col 42}    0.0045{col 52}    0.1598{col 62}    0.1793{col 72}
{txt}  27{col 4}{res}    2.1807{col 14}    1.3082{col 24}    6388{col 32}    0.1997{col 42}    0.0076{col 52}    0.1843{col 62}    0.2142{col 72}
{txt}{hline 72}

{com}. 
.                 renvars lprobust_eval - lprobust_CI_r_rb, postfix(_controls)    
{txt}
{com}.                         
.                 * lp robust: no controls        
.                 lprobust mmargin_nbnn_so trep_date_ulttrans_norm, ///
>                         genvars eval(dots_x_nocontrols)
{res}
Local Polynomial Regression Estimation and Inference.

{txt}{lalign 1: Sample size                              (n=)    }{col 19}{res}          32038
{txt}{lalign 1: Polynomial order for point estimation    (p=)    }{col 19}{res}              1
{txt}{lalign 1: Order of derivative estimated            (v=)    }{col 19}{res}              0
{txt}{lalign 1: Polynomial order for confidence interval (q=)    }{col 19}{res}              2
{txt}{lalign 1: Kernel function                                  }{col 19}{res}{ralign 15: Epanechnikov}
{txt}{lalign 1: Bandwidth selection method                       }{col 19}{res}{ralign 15: imse-dpi}

{txt}{hline 72}
{ralign 4: }{col 4}{ralign 10: }{col 14}{ralign 10: }{col 24}{ralign 8: }{col 32}{ralign 10: Point}{col 42}{ralign 10: Std.}{col 52}{ralign 20: Robust B.C.}{col 72}
{ralign 4: }{col 4}{ralign 10: eval}{col 14}{ralign 10: bw}{col 24}{ralign 8: Eff.n}{col 32}{ralign 10: Est.}{col 42}{ralign 10: Error}{col 52}{ralign 20: 95% Conf. Interval}{col 72}
{hline 72}
   1{col 4}{res}   -2.1653{col 14}    0.7706{col 24}    2173{col 32}    0.1302{col 42}    0.0166{col 52}    0.1003{col 62}    0.1779{col 72}
{txt}   2{col 4}{res}   -1.6575{col 14}    0.7706{col 24}    5577{col 32}    0.0335{col 42}    0.0097{col 52}   -0.0045{col 62}    0.0406{col 72}
{txt}   3{col 4}{res}   -1.4220{col 14}    0.7706{col 24}    7785{col 32}    0.0085{col 42}    0.0074{col 52}   -0.0269{col 62}    0.0083{col 72}
{txt}   4{col 4}{res}   -1.2618{col 14}    0.7706{col 24}    9509{col 32}    0.0013{col 42}    0.0063{col 52}   -0.0264{col 62}    0.0039{col 72}
{txt}   5{col 4}{res}   -1.1362{col 14}    0.7706{col 24}   10870{col 32}    0.0015{col 42}    0.0056{col 52}   -0.0227{col 62}    0.0047{col 72}
{txt}{hline 72}
   6{col 4}{res}   -1.0278{col 14}    0.7706{col 24}   12114{col 32}    0.0062{col 42}    0.0050{col 52}   -0.0166{col 62}    0.0088{col 72}
{txt}   7{col 4}{res}   -0.9305{col 14}    0.7706{col 24}   13150{col 32}    0.0126{col 42}    0.0047{col 52}   -0.0077{col 62}    0.0163{col 72}
{txt}   8{col 4}{res}   -0.8430{col 14}    0.7706{col 24}   14052{col 32}    0.0197{col 42}    0.0044{col 52}    0.0015{col 62}    0.0244{col 72}
{txt}   9{col 4}{res}   -0.7588{col 14}    0.7706{col 24}   14866{col 32}    0.0274{col 42}    0.0041{col 52}    0.0101{col 62}    0.0321{col 72}
{txt}  10{col 4}{res}   -0.6790{col 14}    0.7706{col 24}   15587{col 32}    0.0349{col 42}    0.0040{col 52}    0.0203{col 62}    0.0416{col 72}
{txt}{hline 72}
  11{col 4}{res}   -0.6066{col 14}    0.7706{col 24}   16170{col 32}    0.0422{col 42}    0.0038{col 52}    0.0300{col 62}    0.0507{col 72}
{txt}  12{col 4}{res}   -0.5360{col 14}    0.7706{col 24}   16650{col 32}    0.0496{col 42}    0.0037{col 52}    0.0396{col 62}    0.0598{col 72}
{txt}  13{col 4}{res}   -0.4683{col 14}    0.7706{col 24}   17047{col 32}    0.0570{col 42}    0.0036{col 52}    0.0483{col 62}    0.0682{col 72}
{txt}  14{col 4}{res}   -0.4015{col 14}    0.7706{col 24}   17404{col 32}    0.0644{col 42}    0.0036{col 52}    0.0563{col 62}    0.0759{col 72}
{txt}  15{col 4}{res}   -0.3367{col 14}    0.7706{col 24}   17642{col 32}    0.0718{col 42}    0.0035{col 52}    0.0640{col 62}    0.0833{col 72}
{txt}{hline 72}
  16{col 4}{res}   -0.2751{col 14}    0.7706{col 24}   17868{col 32}    0.0786{col 42}    0.0035{col 52}    0.0712{col 62}    0.0903{col 72}
{txt}  17{col 4}{res}   -0.2114{col 14}    0.7706{col 24}   17954{col 32}    0.0854{col 42}    0.0034{col 52}    0.0786{col 62}    0.0975{col 72}
{txt}  18{col 4}{res}   -0.1502{col 14}    0.7706{col 24}   18003{col 32}    0.0918{col 42}    0.0034{col 52}    0.0856{col 62}    0.1045{col 72}
{txt}  19{col 4}{res}   -0.0884{col 14}    0.7706{col 24}   18013{col 32}    0.0980{col 42}    0.0034{col 52}    0.0924{col 62}    0.1112{col 72}
{txt}  20{col 4}{res}   -0.0246{col 14}    0.7706{col 24}   17985{col 32}    0.1045{col 42}    0.0034{col 52}    0.0987{col 62}    0.1175{col 72}
{txt}{hline 72}
  21{col 4}{res}    0.0395{col 14}    0.7706{col 24}   17882{col 32}    0.1108{col 42}    0.0034{col 52}    0.1046{col 62}    0.1234{col 72}
{txt}  22{col 4}{res}    0.1039{col 14}    0.7706{col 24}   17740{col 32}    0.1169{col 42}    0.0034{col 52}    0.1099{col 62}    0.1288{col 72}
{txt}  23{col 4}{res}    0.1701{col 14}    0.7706{col 24}   17533{col 32}    0.1230{col 42}    0.0035{col 52}    0.1148{col 62}    0.1339{col 72}
{txt}  24{col 4}{res}    0.2388{col 14}    0.7706{col 24}   17232{col 32}    0.1289{col 42}    0.0035{col 52}    0.1208{col 62}    0.1402{col 72}
{txt}  25{col 4}{res}    0.3090{col 14}    0.7706{col 24}   16865{col 32}    0.1350{col 42}    0.0036{col 52}    0.1266{col 62}    0.1463{col 72}
{txt}{hline 72}
  26{col 4}{res}    0.3789{col 14}    0.7706{col 24}   16474{col 32}    0.1408{col 42}    0.0036{col 52}    0.1330{col 62}    0.1530{col 72}
{txt}  27{col 4}{res}    0.4535{col 14}    0.7706{col 24}   15960{col 32}    0.1464{col 42}    0.0037{col 52}    0.1392{col 62}    0.1597{col 72}
{txt}  28{col 4}{res}    0.5319{col 14}    0.7706{col 24}   15346{col 32}    0.1518{col 42}    0.0038{col 52}    0.1451{col 62}    0.1662{col 72}
{txt}  29{col 4}{res}    0.6185{col 14}    0.7706{col 24}   14623{col 32}    0.1570{col 42}    0.0040{col 52}    0.1512{col 62}    0.1728{col 72}
{txt}  30{col 4}{res}    0.7059{col 14}    0.7706{col 24}   13856{col 32}    0.1615{col 42}    0.0041{col 52}    0.1573{col 62}    0.1796{col 72}
{txt}{hline 72}
  31{col 4}{res}    0.8016{col 14}    0.7706{col 24}   13098{col 32}    0.1665{col 42}    0.0043{col 52}    0.1609{col 62}    0.1839{col 72}
{txt}  32{col 4}{res}    0.9000{col 14}    0.7706{col 24}   12180{col 32}    0.1713{col 42}    0.0045{col 52}    0.1634{col 62}    0.1874{col 72}
{txt}  33{col 4}{res}    1.0054{col 14}    0.7706{col 24}   11253{col 32}    0.1775{col 42}    0.0047{col 52}    0.1645{col 62}    0.1897{col 72}
{txt}  34{col 4}{res}    1.1240{col 14}    0.7706{col 24}   10202{col 32}    0.1854{col 42}    0.0050{col 52}    0.1667{col 62}    0.1935{col 72}
{txt}  35{col 4}{res}    1.2643{col 14}    0.7706{col 24}    9015{col 32}    0.1954{col 42}    0.0054{col 52}    0.1704{col 62}    0.1995{col 72}
{txt}{hline 72}
  36{col 4}{res}    1.4277{col 14}    0.7706{col 24}    7798{col 32}    0.2073{col 42}    0.0058{col 52}    0.1823{col 62}    0.2139{col 72}
{txt}  37{col 4}{res}    1.6234{col 14}    0.7706{col 24}    6299{col 32}    0.2269{col 42}    0.0064{col 52}    0.2040{col 62}    0.2380{col 72}
{txt}  38{col 4}{res}    1.8787{col 14}    0.7706{col 24}    4617{col 32}    0.2605{col 42}    0.0076{col 52}    0.2419{col 62}    0.2798{col 72}
{txt}  39{col 4}{res}    2.2787{col 14}    0.7706{col 24}    2499{col 32}    0.3177{col 42}    0.0127{col 52}    0.2861{col 62}    0.3384{col 72}
{txt}{hline 72}

{com}. 
.                 * X-axis locations for labels
.                 quietly sum trep_date_ulttrans
{txt}
{com}.                 local global_mean = r(mean)
{txt}
{com}.                 local global_sd = r(sd)
{txt}
{com}.                 local x1 = (tc(20oct2019 17:30:00) - `global_mean') / `global_sd'
{txt}
{com}.                 local x2 = (tc(20oct2019 18:30:00) - `global_mean') / `global_sd'
{txt}
{com}.                 local x3 = (tc(20oct2019 19:30:00) - `global_mean') / `global_sd'
{txt}
{com}.                 local x4 = (tc(20oct2019 20:30:00) - `global_mean') / `global_sd'
{txt}
{com}. 
.                 * Create figure
.                 twoway (scatter dots_fit_nocontrols dots_x_nocontrols, ///
>                                 msymbol(Th) msize(vsmall) mcolor(midblue)) ///
>                         (line lprobust_gx_bc lprobust_eval, ///
>                                 lcolor(midblue) lwidth(medthick)) ///
>                         (scatter dots_fit dots_x, ///
>                                 msize(vsmall) mcolor(gs6)) ///
>                         (line lprobust_gx_bc_controls lprobust_eval_controls, ///
>                                 lcolor(gs6) lwidth(medthick)) ///
>                         (line lprobust_CI_l_rb lprobust_eval, ///
>                                 lpattern(dash) lcolor(midblue) lwidth(thin)) ///
>                         (line lprobust_CI_r_rb lprobust_eval, ///
>                                 lpattern(dash) lcolor(midblue) lwidth(thin)) ///
>                         (line lprobust_CI_l_rb_controls lprobust_eval_controls, ///
>                                 lpattern(dash) lcolor(gs6) lwidth(thin)) ///
>                         (line lprobust_CI_r_rb_controls lprobust_eval_controls, ///
>                                 lpattern(dash) lcolor(gs6) lwidth(thin)), ///
>                         legend(order(2 4) ring(0) pos(11) cols(1) lab(2 "No controls") ///
>                                 lab(4 "Education, region, and rurality controls")) /// 
>                         graphregion(color(white)) ///
>                         xsize(7) ysize(4.7) ///
>                         ylabel(-0.1(0.1)0.4, angle(0) nogrid)  ///
>                         xlabel(`x1' `" "10/20" "5:30 p.m." "' ///
>                         `x2' `" "10/20" "6:30 p.m." "' ///
>                         `x3' `" "10/20" "7:30 p.m." "' ///
>                         `x4' `" "10/20" "8:30 p.m." "', labsize(small)) ///
>                         ytitle("Average Incumbent Margin") ///
>                         xtitle("Transmission Time") ///
>                         title("")
{res}{txt}
{com}.                 graph export "outputs/generated/Figure_1a.pdf", replace
{txt}(file outputs/generated/Figure_1a.pdf written in PDF format)

{com}. 
.         * Figure 1b
.         *----------
.                 use "data/outputs/computo_ulttranstrepdate_missingsatmunmedian.dta", clear      
{txt}
{com}. 
.                 * Nulos share
.                 gen nulosshare = Nulos / total_so
{txt}(4 missing values generated)

{com}. 
.                 * Margin
.                 gen margin_nbnn = mshare_nbnn - cshare_nbnn
{txt}(4 missing values generated)

{com}. 
.                 * Recinto ID
.                 egen reci_id = group(Pais Dep Prov Muni Loc Reci)
{txt}
{com}. 
.                 * De-mean
.                 foreach var of varlist mshare_nbnn cshare_nbnn margin_nbnn nulosshare {c -(}
{txt}  2{com}.                         egen reci_mean = mean(`var'), by(reci_id)
{txt}  3{com}.                         gen `var'_dm = `var' - reci_mean 
{txt}  4{com}.                         drop reci_mean
{txt}  5{com}.                         qui su `var'
{txt}  6{com}.                         gen `var'_dm_plus = `var'_dm + `r(mean)' // Add overall mean for scale
{txt}  7{com}.                 {c )-}
{txt}(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)

{com}. 
.                 * Trimming
.                 cumul trep_date_ulttrans, gen(cum_date)
{txt}
{com}.                 drop if cum_date <= 0.02 | cum_date >= 0.98
{txt}(1,387 observations deleted)

{com}.                 drop cum_date
{txt}
{com}.                 
.                 * Without this, Stata can't calculate the right ROT bandwidth
.                 su trep_date_ulttrans, d

                {txt}Last transmission time stamp
{hline 61}
      Percentiles      Smallest
 1%    {res} 1.89e+12       1.89e+12
{txt} 5%    {res} 1.89e+12       1.89e+12
{txt}10%    {res} 1.89e+12       1.89e+12       {txt}Obs         {res}     33,168
{txt}25%    {res} 1.89e+12       1.89e+12       {txt}Sum of Wgt. {res}     33,168

{txt}50%    {res} 1.89e+12                      {txt}Mean          {res} 1.89e+12
                        {txt}Largest       Std. Dev.     {res}  2474736
{txt}75%    {res} 1.89e+12       1.89e+12
{txt}90%    {res} 1.89e+12       1.89e+12       {txt}Variance      {res} 6.12e+12
{txt}95%    {res} 1.89e+12       1.89e+12       {txt}Skewness      {res} .1012129
{txt}99%    {res} 1.89e+12       1.89e+12       {txt}Kurtosis      {res} 2.749301
{txt}
{com}.                 local global_mean = r(mean)
{txt}
{com}.                 local global_sd = r(sd)
{txt}
{com}.                 gen trep_date_ulttrans_norm = (trep_date_ulttrans - `global_mean') / `global_sd'
{txt}
{com}. 
.                 * Binned data using binsreg and all booths
.                 tempfile temp
{txt}
{com}.                 binsreg margin_nbnn_dm trep_date_ulttrans_norm, savedata(`temp') 
{txt}Sorting dataset on trep_date_ulttrans_norm...
Note: This step is omitted if dataset already sorted by trep_date_ulttrans_norm.
{res}
{txt}Binscatter plot
Bin selection method: IMSE-optimal plug-in choice
Placement: Quantile-spaced
Derivative: 0
Output file: C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000001.tmp.dta

{hline 30}{c TT}{hline 15}
{lalign 1:# of observations}{col 30} {c |} {col 32}{res}  33165
{txt}{lalign 1:# of distinct values}{col 30} {c |} {col 32}{res}  10076
{txt}{lalign 1:# of clusters}{col 30} {c |} {col 32}{res}      .
{txt}{hline 30}{c +}{hline 15}
{lalign 1:Bin selection:}{col 30} {c |} 
{ralign 29:Degree of polynomial}{col 30} {c |} {col 32}{res}      0
{txt}{ralign 29:# of smoothness constraints}{col 30} {c |} {col 32}{res}      0
{txt}{ralign 29:# of bins}{col 30} {c |} {col 32}{res}     26
{txt}{hline 30}{c BT}{hline 15}

{hline 9}{c TT}{hline 30}
{col 10}{c |}{col 17}p{col 25}s{col 33}df
{hline 9}{c +}{hline 30}
{lalign 1: dots}{col 10}{c |}{col 17}0{col 25}0{col 33}26
{hline 9}{c BT}{hline 30}
{res}{txt}
{com}. 
.                 gen dots_binid = _n
{txt}
{com}.                 merge 1:1 dots_binid using `temp'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          33,142
{txt}{col 9}from master{col 30}{res}          33,142{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}              26{txt}  (_merge==3)
{col 5}{hline 41}

{com}.                 drop _merge
{txt}
{com}. 
.                 * nonparametric fit
.                 lprobust margin_nbnn_dm trep_date_ulttrans_norm, genvars
{res}
Local Polynomial Regression Estimation and Inference.

{txt}{lalign 1: Sample size                              (n=)    }{col 19}{res}          33165
{txt}{lalign 1: Polynomial order for point estimation    (p=)    }{col 19}{res}              1
{txt}{lalign 1: Order of derivative estimated            (v=)    }{col 19}{res}              0
{txt}{lalign 1: Polynomial order for confidence interval (q=)    }{col 19}{res}              2
{txt}{lalign 1: Kernel function                                  }{col 19}{res}{ralign 15: Epanechnikov}
{txt}{lalign 1: Bandwidth selection method                       }{col 19}{res}{ralign 15: imse-dpi}

{txt}{hline 72}
{ralign 4: }{col 4}{ralign 10: }{col 14}{ralign 10: }{col 24}{ralign 8: }{col 32}{ralign 10: Point}{col 42}{ralign 10: Std.}{col 52}{ralign 20: Robust B.C.}{col 72}
{ralign 4: }{col 4}{ralign 10: eval}{col 14}{ralign 10: bw}{col 24}{ralign 8: Eff.n}{col 32}{ralign 10: Est.}{col 42}{ralign 10: Error}{col 52}{ralign 20: 95% Conf. Interval}{col 72}
{hline 72}
   1{col 4}{res}   -1.8045{col 14}    2.4103{col 24}   24256{col 32}   -0.0039{col 42}    0.0015{col 52}   -0.0067{col 62}    0.0003{col 72}
{txt}   2{col 4}{res}   -1.4767{col 14}    2.4103{col 24}   27162{col 32}   -0.0036{col 42}    0.0011{col 52}   -0.0058{col 62}   -0.0013{col 72}
{txt}   3{col 4}{res}   -1.2715{col 14}    2.4103{col 24}   28641{col 32}   -0.0033{col 42}    0.0010{col 52}   -0.0053{col 62}   -0.0015{col 72}
{txt}   4{col 4}{res}   -1.1135{col 14}    2.4103{col 24}   29559{col 32}   -0.0030{col 42}    0.0009{col 52}   -0.0049{col 62}   -0.0015{col 72}
{txt}   5{col 4}{res}   -0.9858{col 14}    2.4103{col 24}   30208{col 32}   -0.0027{col 42}    0.0008{col 52}   -0.0045{col 62}   -0.0014{col 72}
{txt}{hline 72}
   6{col 4}{res}   -0.8714{col 14}    2.4103{col 24}   30743{col 32}   -0.0024{col 42}    0.0007{col 52}   -0.0042{col 62}   -0.0012{col 72}
{txt}   7{col 4}{res}   -0.7660{col 14}    2.4103{col 24}   31146{col 32}   -0.0021{col 42}    0.0007{col 52}   -0.0039{col 62}   -0.0010{col 72}
{txt}   8{col 4}{res}   -0.6645{col 14}    2.4103{col 24}   31504{col 32}   -0.0019{col 42}    0.0006{col 52}   -0.0036{col 62}   -0.0007{col 72}
{txt}   9{col 4}{res}   -0.5764{col 14}    2.4103{col 24}   31780{col 32}   -0.0016{col 42}    0.0006{col 52}   -0.0033{col 62}   -0.0005{col 72}
{txt}  10{col 4}{res}   -0.4871{col 14}    2.4103{col 24}   32044{col 32}   -0.0014{col 42}    0.0006{col 52}   -0.0030{col 62}   -0.0002{col 72}
{txt}{hline 72}
  11{col 4}{res}   -0.4007{col 14}    2.4103{col 24}   32269{col 32}   -0.0012{col 42}    0.0006{col 52}   -0.0027{col 62}    0.0001{col 72}
{txt}  12{col 4}{res}   -0.3186{col 14}    2.4103{col 24}   32467{col 32}   -0.0010{col 42}    0.0006{col 52}   -0.0024{col 62}    0.0003{col 72}
{txt}  13{col 4}{res}   -0.2382{col 14}    2.4103{col 24}   32570{col 32}   -0.0007{col 42}    0.0005{col 52}   -0.0021{col 62}    0.0006{col 72}
{txt}  14{col 4}{res}   -0.1610{col 14}    2.4103{col 24}   32674{col 32}   -0.0005{col 42}    0.0005{col 52}   -0.0018{col 62}    0.0009{col 72}
{txt}  15{col 4}{res}   -0.0822{col 14}    2.4103{col 24}   32699{col 32}   -0.0003{col 42}    0.0005{col 52}   -0.0015{col 62}    0.0012{col 72}
{txt}{hline 72}
  16{col 4}{res}    0.0002{col 14}    2.4103{col 24}   32716{col 32}   -0.0001{col 42}    0.0005{col 52}   -0.0012{col 62}    0.0015{col 72}
{txt}  17{col 4}{res}    0.0806{col 14}    2.4103{col 24}   32724{col 32}    0.0001{col 42}    0.0005{col 52}   -0.0010{col 62}    0.0017{col 72}
{txt}  18{col 4}{res}    0.1646{col 14}    2.4103{col 24}   32737{col 32}    0.0004{col 42}    0.0005{col 52}   -0.0007{col 62}    0.0020{col 72}
{txt}  19{col 4}{res}    0.2527{col 14}    2.4103{col 24}   32716{col 32}    0.0006{col 42}    0.0005{col 52}   -0.0004{col 62}    0.0023{col 72}
{txt}  20{col 4}{res}    0.3420{col 14}    2.4103{col 24}   32600{col 32}    0.0008{col 42}    0.0005{col 52}   -0.0002{col 62}    0.0026{col 72}
{txt}{hline 72}
  21{col 4}{res}    0.4358{col 14}    2.4103{col 24}   32462{col 32}    0.0011{col 42}    0.0006{col 52}    0.0001{col 62}    0.0029{col 72}
{txt}  22{col 4}{res}    0.5324{col 14}    2.4103{col 24}   32247{col 32}    0.0013{col 42}    0.0006{col 52}    0.0004{col 62}    0.0032{col 72}
{txt}  23{col 4}{res}    0.6435{col 14}    2.4103{col 24}   32007{col 32}    0.0016{col 42}    0.0006{col 52}    0.0006{col 62}    0.0034{col 72}
{txt}  24{col 4}{res}    0.7570{col 14}    2.4103{col 24}   31664{col 32}    0.0018{col 42}    0.0006{col 52}    0.0008{col 62}    0.0037{col 72}
{txt}  25{col 4}{res}    0.8851{col 14}    2.4103{col 24}   31237{col 32}    0.0021{col 42}    0.0007{col 52}    0.0011{col 62}    0.0040{col 72}
{txt}{hline 72}
  26{col 4}{res}    1.0201{col 14}    2.4103{col 24}   30619{col 32}    0.0024{col 42}    0.0007{col 52}    0.0013{col 62}    0.0043{col 72}
{txt}  27{col 4}{res}    1.1765{col 14}    2.4103{col 24}   29726{col 32}    0.0027{col 42}    0.0008{col 52}    0.0014{col 62}    0.0045{col 72}
{txt}  28{col 4}{res}    1.3664{col 14}    2.4103{col 24}   28316{col 32}    0.0030{col 42}    0.0009{col 52}    0.0015{col 62}    0.0049{col 72}
{txt}  29{col 4}{res}    1.6092{col 14}    2.4103{col 24}   26047{col 32}    0.0033{col 42}    0.0010{col 52}    0.0013{col 62}    0.0052{col 72}
{txt}  30{col 4}{res}    1.9438{col 14}    2.4103{col 24}   22218{col 32}    0.0038{col 42}    0.0013{col 52}    0.0002{col 62}    0.0056{col 72}
{txt}{hline 72}

{com}. 
.                 * X-axis locations for labels
.                 sum trep_date_ulttrans

{txt}    Variable {c |}        Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 57}
trep_date_~s {c |}{res}     33,168    1.89e+12     2474736   1.89e+12   1.89e+12
{txt}
{com}.                 local global_mean = r(mean)
{txt}
{com}.                 local global_sd = r(sd)
{txt}
{com}.                 local x1 = (tc(20oct2019 17:30:00) - `global_mean') / `global_sd'
{txt}
{com}.                 local x2 = (tc(20oct2019 18:30:00) - `global_mean') / `global_sd'
{txt}
{com}.                 local x3 = (tc(20oct2019 19:30:00) - `global_mean') / `global_sd'
{txt}
{com}.                 local x4 = (tc(20oct2019 20:30:00) - `global_mean') / `global_sd'
{txt}
{com}.         
.                 * Create figures
.                 twoway (scatter dots_fit dots_x, msize(small) mcolor(midblue)) ///
>                         (line lprobust_gx_bc lprobust_eval, ///
>                                 lcolor(gs6) lwidth(medthick)) ///
>                         (line lprobust_CI_l_rb lprobust_eval, ///
>                                 lcolor(gs6) lwidth(thin) lpattern(dash)) ///
>                         (line lprobust_CI_r_rb lprobust_eval, ///
>                                 lcolor(gs6) lwidth(thin) lpattern(dash)), ///
>                         xlabel(`x1' `" "10/20" "5:30 p.m." "' ///
>                         `x2' `" "10/20" "6:30 p.m." "' ///
>                         `x3' `" "10/20" "7:30 p.m." "' ///
>                         `x4' `" "10/20" "8:30 p.m." "', labsize(small)) ///
>                         graphregion(color(white)) ///
>                         ylab(, glcolor(none) angle(0)) ///
>                         ytitle("De-meaned Average Incumbent Margin") ///
>                         xtitle("Transmission Time") ///
>                         xsize(7) ysize(4.7) ///
>                         legend(off)
{res}{txt}
{com}.                 graph export "outputs/generated/Figure_1b.pdf", replace
{txt}(file outputs/generated/Figure_1b.pdf written in PDF format)

{com}. 
. *------------------------------------------------------------------------------*
. timer off 2
{txt}
{com}. timer list 2
{res}   2:    647.11 /        1 =     647.1130
{txt}
{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}E:\Github\Bolivia\00_replication_files\log-files/2_Figure_1.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}25 Jan 2022, 21:39:32
{txt}{.-}
{smcl}
{txt}{sf}{ul off}